<template>
  <div class="account_mag" style="text-align: center" v-if="uName">
    <van-image
      style="margin: 7px 0"
      width="100"
      height="100"
      :src="headImg"
    />
    <van-field v-model="uName" label="我的账号" input-align="right" disabled />
    <van-field v-model="uNick" label="我的昵称" input-align="right" />
    <van-button type="primary" block style="width: 80%;margin: 7px auto" @click="save">保存</van-button>
  </div>
</template>

<script>
// import {Toast} from "vant";

import {modifyNickname} from "../http/api";
import qs from "qs";
import {Notify} from "vant";

export default {
  name: "AccountMag",
  inject: ['reload'],
  data() {
    return {
      uName: JSON.parse(localStorage.getItem('user')).u_name,
      uNick: JSON.parse(localStorage.getItem('user')).u_nickname,
      headImg: JSON.parse(localStorage.getItem('user')).u_img
    }
  },
  methods: {
    save() {
      modifyNickname(qs.stringify({
        nickname: this.uNick,
        user: JSON.parse(localStorage.getItem('user')).u_name
      })).then(res => {
        localStorage.setItem('user', JSON.stringify(res.data))
        Notify(res.msg)
        this.$router.push('/my')
      })
    }
  }
}
</script>

<style scoped>

</style>
